#include <stdio.h>
#include "prg_list.h"
#include "des_list.h"

PRGELEM* PRGELEM_malloc(int prg_num, int prg_type, char *pro_name, int pmt_pid, int pcr_pid) {
	PRGELEM *prg_elem;
	
	if(!pro_name) return NULL;
	
	prg_elem = (PRGELEM*)os_calloc(sizeof(PRGELEM));
	if(!prg_elem) return NULL;

	prg_elem->prg_num = prg_num & 0xFFFF;
	prg_elem->prg_type = prg_type;
	snprintf(prg_elem->prg_name, sizeof(prg_elem->prg_name), "%s%03d", pro_name, prg_num);
	snprintf(prg_elem->pro_name, sizeof(prg_elem->pro_name), "%s"    , pro_name);
	prg_elem->pmt_pid = pmt_pid & 0x1FFF;
	prg_elem->pcr_pid = pcr_pid & 0x1FFF;

	DESELEM_LIST_init(&prg_elem->pmt_des_list);
	ESELEM_LIST_init( &prg_elem->es_list);
	DESELEM_LIST_init(&prg_elem->sdt_des_list);

	return prg_elem;
}

void PRGELEM_free(PRGELEM *prg_elem) {
	if(!prg_elem) return;

	DESELEM_LIST_free(&prg_elem->pmt_des_list);
	ESELEM_LIST_free( &prg_elem->es_list);
	DESELEM_LIST_free(&prg_elem->sdt_des_list);

	os_free(prg_elem);
}

LIST_XXXX(PRGELEM, node);
